'use strict';
const Mock = require('mock')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	let body = event.body
	let paths = event.path.split('/')
	if (event.isBase64Encoded) {
		body = Buffer.from(body)
	}
	let projectId = ''
	let projectApi = ''
	let apiPath = ''
	if (paths.length > 2) {
		let pathData = paths.filter(v => v !== '')
		projectId = pathData[0]
		projectApi = '/' + pathData[1]
		apiPath = ''
		paths.forEach((v, i) => {
			if (i > 2) {
				apiPath += '/' + v
			}
		})
		if (apiPath === '' || apiPath === '/') {
			return {
				code: 3,
				desc: '接口访问错误'
			}
		} else {
			console.log(projectId);
			console.log(projectApi);
			console.log(apiPath);
		}
	} else {
		return {
			code: 2,
			desc: '权限不足'
		}
	}
	// console.log(Mock());
	//返回数据给客户端
	return {
		projectId,
		projectApi,
		apiPath,
	}
};
